﻿@{
    ViewBag.Title = "Form";
    Layout = "~/Views/Shared/_Form.cshtml";
}
<script>
    var keyValue = $.request("keyValue");
    console.log(keyValue);
    $(function () {
        $("#Class").bindSelect({
            url: "/SystemManage/ItemsData/GetSelectJson",
            param: { enCode: "Class" }
        });
        $("#SchoolId").bindSelect({
            url: "/Gas/School/GetSchoolSelectJson",
        });
        if (null != keyValue && "" != keyValue) {
            $.ajax({
                url: "/Gas/Class/GetFormJsonForUpdate",
                data: { keyValue: keyValue },
                dataType: "json",
                async: false,
                success: function (data) {
                    console.log(data);
                    $("#form1").formSerialize(data);
                }
            });
        } else {
            initControl();
        }
    });
    function initControl() {
        $.ajax({
            url: "/Gas/Class/GetMaxSortId",
            dataType: "json",
            async: false,
            success: function (data) {
                $("#SortId").val(data); //新增时,初始化排序号
            }
        });
    }
    function submitForm() {
        if (!$('#form1').formValid()) {
            return false;
        }
        if (!checkInt()) {
            return false;
        }
        $.submitForm({
            url: "/Gas/Class/SubmitForm?keyValue=" + keyValue,
            param: $("#form1").formSerialize(),
            success: function () {
                $.currentWindow().$("#gridList").trigger("reloadGrid");
            }
        })
    }
    //数字校验
    function checkInt() {
        var txtClassFreeTotalAmount = $("#ClassFreeTotalAmount").val();
        var re = new RegExp("^[1-9]\d*|0$");
        if (txtClassFreeTotalAmount != "") {
            if (!re.test(txtClassFreeTotalAmount)) {
                bootbox.alert("年级学位总数输入不合法，请输入数字");
                return false;
            }
        }
        return true;
    }
</script>

<form id="form1">
    <div style="padding-top: 20px; margin-right: 20px;">
        <table class="form">
            <tr>
                <th class="formTitle">学校名称</th>
                <td class="formValue">
                    <select id="SchoolId" name="SchoolId" class="form-control required"></select>
                </td>
            </tr>
            <tr>
                <th class="formTitle">年级</th>
                <td class="formValue">
                    <select id="Class" name="Class" class="form-control required"></select>
                </td>
            </tr>
            <tr>
                <th class="formTitle">年级学位总数</th>
                <td class="formValue">
                    <input id="ClassFreeTotalAmount" name="ClassFreeTotalAmount" type="text" class="form-control required" placeholder="请输入年级学位剩余数"/>
                </td>
            </tr>
            @*<tr>
            <th class="formTitle">年级学位剩余数</th>
            <td class="formValue">
                <input id="ClassFreeAmount" name="ClassFreeAmount" type="text" class="form-control" placeholder="请输入年级学位剩余数" />
            </td>
        </tr>*@
            <tr>
                <th class="formTitle" valign="top" style="padding-top: 5px;">
                    备注
                </th>
                <td class="formValue">
                    <textarea id="Content" name="Content" class="form-control" style="height: 60px;"></textarea>
                </td>
            </tr>
            <tr>
                <th class="formTitle" style="height: 35px;">选项</th>
                <td class="formValue" style="padding-top: 1px;">
                    <div class="ckbox">
                        <input id="isEnable" name="isEnable" type="checkbox" checked="checked"><label for="isEnable">有效</label>
                    </div>
                </td>
            </tr>
            <tr>
                <th class="formTitle">排序号</th>
                <td class="formValue">
                    <input id="SortId" name="SortId" type="text" class="form-control required" placeholder="排序号" disabled />
                </td>
            </tr>
        </table>
    </div>
</form>
